
<template>
  <div class="execution">
    <basic-container>
      <avue-crud
        :permission="permissionList"
        v-model="form"
        v-bind="bindVal"
        v-on="onEvent"
        :page.sync="page"
      >
        <template slot="menuLeft">
          <el-button type="primary" size="small" @click="handleExport">导 出</el-button>
        </template>
      </avue-crud>
    </basic-container>
  </div>
</template>

<script>
import {
  fetchList,
  getObj,
  addObj,
  putObj,
  delObj,
  exportExcel,
  delBatch,
  noticeBatch
} from "@/api/subwaystm/swstconductorfareconsolidationnotice";
import { tableOption } from "@/const/crud/subwaystm/swstconductorfareconsolidationnoticeother";
import { mapGetters } from "vuex";
import baseCrud from '@/mixins/base-crud'

export default {
  name: "swstconductorfareconsolidationnotice",
  mixins: [baseCrud('subwaystm/swstconductorfareconsolidationnoticeother')],
  data() {
    return {
      form: {}
    };
  },
  watch: {
    "form.mergePerson": function() {
      this.form.mergePersonCode = this.form.mergePerson;
    },
    "form.mergePerson2": function() {
      this.form.mergePerson2Code = this.form.mergePerson2;
    }
  },
  computed: {
    ...mapGetters(["permissions"]),
    permissionList() {
      return {
        addBtn: this.vaildData(
          this.permissions.stm_swstconductorfareconsolidationnotice_add,
          false
        ),
        delBtn: this.vaildData(
          this.permissions.stm_swstconductorfareconsolidationnotice_del,
          false
        ),
        editBtn: this.vaildData(
          this.permissions.stm_swstconductorfareconsolidationnotice_edit,
          false
        )
      };
    }
  },
  methods: {
    delBO: function() {
      if (this.$refs.crud.tableSelect.length < 1) {
        this.$message.error("请选择数据");
        return false;
      }
      let ids = [];
      for (const table of this.$refs.crud.tableSelect) {
         if (table.dataSource == "0" && table.noticeStatus != "0"){
              this.$message.error("请检查数据，只能删除自己提交的且未通知的");
        return false;
      }
        if (table.dataSource == "0" && table.noticeStatus == "0") {
          ids.push(table);
        }
      }
      delBatch(ids)
        .then(data => {
          this.$message.success("删除成功");
          done();
          this.getList(this.page);
        })
        .catch(() => {
          loading();
        });
    },

    noticeO: function() {
      if (this.$refs.crud.tableSelect.length < 1) {
        this.$message.error("请选择数据");
        return false;
      }
      let ids = [];
      for (const table of this.$refs.crud.tableSelect) {
          if(table.noticeStatus!='0'){
              this.$message.error("请检查勾选数据,不要重复通知");
              return false;
            }
        ids.push(table);
      }
      noticeBatch(ids)
        .then(data => {
          this.$message.success("通知成功");
           this.getList(this.page);
          done();

        })
        .catch(() => {
          loading();
        });
    }
  }
};
</script>
